﻿using MediatR;
using Sowrk03_28.Repository;
using Swork03_28.Api.Application.Commands.SlaughterCommand;
using Swork03_28.Domain.TraceableInfos;

namespace Swork03_28.Api.Application.CommandHandlers.SlaughterCommandHandler
{
    public class SlaughterSelectCommandHandler : IRequestHandler<SlaughterSelectCommand, Slaughter>
    {
        private readonly IRepository<Slaughter> _repository;

        public SlaughterSelectCommandHandler(IRepository<Slaughter> repository)
        {
            _repository = repository;
        }

        public async Task<Slaughter> Handle(SlaughterSelectCommand request, CancellationToken cancellationToken)
        {
            var info = await _repository.GetValues(x => x.BatchId == request.BatchId);
            var data = info.FirstOrDefault();
            if (data == null)
            {
                return null;
            }
            return data;
        }
    }
}
